//
//  InputValueViewController.swift
//  SwiftStudy
//
//  Created by wangtian on 15/7/14.
//  Copyright (c) 2015年 wangtian. All rights reserved.
//

import UIKit

@objc
protocol PassValueProtocol : NSObjectProtocol{

    @objc optional func passValueFunc(_ needPassValue:String) -> Void
    
}

typealias PassValueBlock = (_ passValue:String) -> ()

class InputValueViewController: UIViewController {

   @IBOutlet weak var inputTextField: UITextField!
    var passValueBlock:PassValueBlock?
    weak var passValueDelegate:PassValueProtocol?
    dynamic var observerStr : NSString?
    override func viewDidLoad() {
        
        super.viewDidLoad()
        self.title = "输入值页面"
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func backToLastPage(_ sender: UIButton) {
        
        if self.passValueBlock != nil {
            
            self.passValueBlock!(self.inputTextField.text!)
        }
        
        if  self.passValueDelegate != nil{
            
            let selector = #selector(PassValueProtocol.passValueFunc(_:))
            
            if  self.passValueDelegate!.responds(to: selector){
                
                self.passValueDelegate!.passValueFunc!(self.inputTextField.text!)
            }
        }
        
        NotificationCenter.default.post(name: Notification.Name(rawValue: "PassWord"), object: self.inputTextField.text)
        
        self.navigationController!.popViewController(animated: true)
    }
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        self.view.endEditing(true)
    }
    
}
